<template>
  <j-modal
    :title="title"
    :width="980"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleApprove"
    @cancel="close"
    cancelText="关闭"
    okText="确定"
  >

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row class="form-row" :gutter="24">
          <a-col :sm="12">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="审批结果">
              <j-dict-select-tag
                v-decorator="['approveStatus', validatorRules.approveStatus]"
                @change="handleWarehouseFlag"
                :type="'radioButton'"
                :triggerChange="true"
                dictCode="discountApproveReview_status"
              />
            </a-form-item>
            <a-form-item
              :hidden="this.approveStatus == 1"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="拒绝备注"
            >
              <a-textarea
                v-if="this.approveStatus != 1"
                :rows="1"
                placeholder="请输入拒绝备注"
                v-decorator="['approveReason', validatorRules.approveReason]"
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import {httpAction, getAction, postAction} from '@/api/manage'
import {ACCESS_TOKEN} from "@/store/mutation-types"
import pick from 'lodash.pick'
import moment from 'moment'
import JDictSelectTag from '../../../components/dict/JDictSelectTag'
import Vue from 'vue'
import StmReplenishmentModal from "./StmReplenishmentModal";
import StmRequiregoodsModal from "./StmRequiregoodsModal";
import StmReplenishmentExecModal from "./StmReplenishmentExecModal";
import StmReplenishmentItemModal from "./StmReplenishmentItemModal";
import StmRequiregoodsItemList from "../StmRequiregoodsItemList";
import StmReplenishmentPrintModal from "./StmReplenishmentPrintModal";
import areaDataJson from "@/utils/area_mini.json";

export default {
  name: 'StmDealerInfoDiscountApprove',
  components: {JDictSelectTag},
  data() {
    return {
      title: '操作',
      visible: false,
      model: {},
      approveStatus: "1",
      labelCol: {
        xs: {span: 24},
        sm: {span: 5}
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16}
      },
      labelCol1: {
        xs: {span: 24},
        sm: {span: 8}
      },
      wrapperCol1: {
        xs: {span: 24},
        sm: {span: 12}
      },
      editEnable: true,
      hiding: true,
      confirmLoading: false,
      form: this.$form.createForm(this),
      ids: '',
      approveReason: "",
      url: {
        auditBatch: '/stm/stmDealerDiscount/auditBatch',
      },
      validatorRules: {
        approveStatus: {rules: [{required: true, message: '请选择审批结果!'}]},
        approveReason: {rules: [{required: true, message: "请输入拒绝原因!"}]}

      },

    }
  },
  created() {
    const token = Vue.ls.get(ACCESS_TOKEN);
    this.headers = {"X-Access-Token": token};
  },
  computed: {},
  methods: {

    edit(ids) {
      this.ids=ids;
      this.approveStatus = "1";
      this.visible = true
      this.model = Object.assign({}, {})
      this.model.approveStatus=this.approveStatus;
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model, 'approveStatus'))
      })
    },

    handleApprove() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          let formData = Object.assign(this.model, values)
          formData.auditType = this.approveStatus;
          formData.ids = this.ids;
          formData.note = this.form.getFieldValue("approveReason");
          postAction(this.url.auditBatch, formData).then((res) => {
            if (res.success) {
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
            that.close()
          })
        }
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },

    handleWarehouseFlag(e) {
      this.approveStatus = e;
    },
  }
}
</script>

<style lang="less" scoped>

</style>
